<template>
  <div id="HealthLogList">
    <van-nav-bar title="历史复康日志" left-arrow left-text="返回" @click-left="onClickLeft" fixed 
      placeholder></van-nav-bar>
    <div class="main" v-if="list.length">
      <div
        class="box"
        v-for="item in list"
        :key="item.id"
        @click="toDetails(item)"
      >
        <div class="top date">
          <div class="topLeft">{{(item.log_date || '').split(' ')[0]}}</div>
          <div
            class="topRight"
          >{{item.nengliang_bili >=70 && item.danbaizhi_bili >=70 ? '已完成' : '未完成'}}</div>
        </div>
        <div class="content">
          <div class="content_box">
            <div class="energy">
              <div class="energyLeft">
                <div class="title">推荐能量</div>
                <div class="unit">{{item.nengliang}} kcal</div>
              </div>
              <div class="energyRight">
                <div class="completion">完成率</div>
                <div class="percentage">{{item.nengliang_bili}}%</div>
                <div class="completion">{{item.nengliang_bili >=70 ? '已达标' : '未达标'}}</div>
              </div>
            </div>
            <div class="protein">
              <div class="proteinLeft">
                <div class="title">推荐蛋白质</div>
                <div class="unit">{{item.danbaizhi}} g</div>
              </div>
              <div class="proteinRight">
                <div class="completion">完成率</div>
                <div class="percentage">{{item.danbaizhi_bili}}%</div>
                <div class="completion">{{item.danbaizhi_bili >=70 ? '已达标' : '未达标'}}</div>
              </div>
            </div>
          </div>
          <div class="mhc">
            当天膳食评分：
            <span style="color:red">{{item.pingfen}}</span> 分
          </div>
        </div>
      </div>
    </div>
    <van-empty image="error" description="暂无数据" v-if="list.length === 0" />
  </div>
</template>

<script>
import { jiankanglog } from "@/apis/record";
export default {
  data() {
    return {
      detailId: null,
      list: [],
    };
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1); //返回上一层
    },
    toDetails(item){
      console.log(item)
      if(item.yemian == 1){
        this.$router.push(`/HealthLogDetails/${item.id}`)
      }else{
        this.$router.push(`/logDetails/${item.id}`)
      }
      
    },
    records() {
      jiankanglog({ pid: this.detailId,page:"1"})
        .then((res) => {
          this.list = res.data.list;
          console.log(res);
        })
        .catch((err) => {
          if(err.msg){
            this.$toast(err.msg);
          }else{
            this.$toast("网络错误"); 
          }
        });
    },
  },
  mounted() {
    this.records();
  },
  created() {
    this.detailId = this.$route.params.pid;
  },
};
</script>

<style lang="less">
html {
  min-height: 100vh;
  background-color: #fff;
}
#HealthLogList {
  .van-icon,.van-nav-bar__text {
    color: #404040;
  }
  .main {
    padding: 0 20px;
    min-height: 100%;
    background-color: #fff;
    .box {
      padding: 15px 0;
      border-top: 1px solid #d2d2d2;
      .top {
        display: flex;
        align-items: center;
        justify-content: space-between;
        .topLeft {
          font-family: SourceHanSansCN;
          font-size: 15px;
          color: #151515;
        }
        .topRight {
          font-family: SourceHanSansCN;
          font-size: 15px;
          color: #4e8af4;
        }
      }
      .content {
        .content_box {
          margin-top: 15px;
          text-align: left;
          display: flex;
          align-items: center;
          .energy,
          .protein {
            display: flex;
            align-items: center;
          }
          .protein {
            margin-left: 30px;
          }
          .energyRight,
          .proteinRight {
            width: 56px;
            height: 56px;
            padding: 5px 0;
            border-radius: 50%;
            margin-left: 20px;
            background: linear-gradient(
              132deg,
              rgba(104, 169, 243, 1) 0%,
              rgba(57, 122, 234, 1) 100%
            );
            text-align: center;
            color: #fff;
          }
          .title {
            font-size: 15px;
            color: #151515;
          }
          .unit {
              text-align: right;
            font-size: 15px;
            color: #3b8afc;
          }
          .completion {
            font-size: 10px;
            // transform: scale(0.8);
          }
          .percentage {
            font-size: 17.5px;
            // margin: 2px 0;
          }
        }
        .mhc{
            margin-top: 10px;
            font-size: 15px;
        }
      }
    }
  }
}
</style>
